package modele.cases;

import java.util.Collection;
import java.util.TreeMap;


public class Cases {

	private TreeMap<Integer, CaseInterface> cases;
	private int maxX;
	private int maxY;

	public Cases(int maxX, int maxY) {
		this.maxX = maxX;
		this.maxY = maxY;
		cases = new TreeMap<Integer, CaseInterface>();

	}

	public Cases() {
		cases = new TreeMap<Integer, CaseInterface>();
	}

	public void put(int i, CaseInterface cas) {
		cases.put(i, cas);
		
	}

	public Collection<CaseInterface> getCases() {
		return cases.values();
	}

	public CaseInterface get(int i, int j) {
		if (i < 1) {
			i = maxX;
		}
		if (j < 1) {
			j = maxY;
		}
		if (i > maxX) {
			i = 1;
		}
		if (j > maxY) {
			j = 1;
		}
		for (CaseInterface cas : cases.values()) {
			if (cas.getX() == i && cas.getY() == j) {
				return cas;
			}
		}
		return null;
	}
}
